package algorithm;

public class leetcode_0303 {
    class NumArray {

        private int[] nums;
        private int [] pre;

        public NumArray(int[] nums) {
            this.nums = nums;
            this.pre = new int[nums.length+1];
            this.pre[0] = 0;
            for(int i=1;i<nums.length+1;++i){
                this.pre[i] = this.pre[i-1] + nums[i-1];
            }
        }

        public int sumRange(int left, int right) {
            return this.pre[right+1]-this.pre[left];
        }
    }
}
